package com.lqq.designPattern.behavioral_pattern.observer;

import java.util.ArrayList;
import java.util.List;

//公众号（具体被观察者）
public class SubscriptionSubject implements Subject{
    //储存订阅公众号的微信用户
    private List<Observer> weiXinUserList = new ArrayList<>();
    //添加粉丝
    @Override
    public void attach(Observer observer) {
        weiXinUserList.add(observer);
    }
    //删除粉丝
    @Override
    public void detach(Observer observer) {
        weiXinUserList.remove(observer);
    }
    //发送更新消息给粉丝
    @Override
    public void notify(String msg) {
        for (Observer observer : weiXinUserList) {
            observer.update(msg);
        }
    }
}
